package com.dykj.fireFighting.server.monitoringCenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.dykj.fireFighting.api.monitoringCenter.entity.CityDevice;
import com.dykj.fireFighting.api.monitoringCenter.service.ICityDeviceService;
import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.server.monitoringCenter.mapper.CityDeviceMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author JacksonTu
 * @Date 2021-07-20 15:54:56
 */
@Slf4j
@DubboService
@Transactional(rollbackFor = Exception.class)
public class CityDeviceServiceImpl extends BaseServiceImpl<CityDeviceMapper, CityDevice> implements ICityDeviceService {

    @Override
    public List<CityDevice> getList(String unitId, String name) {
        LambdaQueryWrapper<CityDevice> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(unitId)) {
            wrapper.eq(CityDevice::getUnitId, unitId);
        }
        if (StringUtils.isNotBlank(name)) {
            wrapper.like(CityDevice::getName, name);
        }
        wrapper.eq(CityDevice::getIsDel, 0);

        return this.baseMapper.selectList(wrapper);
    }


    @Override
    public boolean deleteById(String id) {
        UpdateWrapper<CityDevice> wrapper = new UpdateWrapper<>();
        CityDevice cityDevice = new CityDevice();
        cityDevice.setIsDel(1);

        wrapper.eq("id", id);
        this.baseMapper.update(cityDevice, wrapper);

        return true;
    }


}
